// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   SimpleJDKLoggingHook.java

package org.quickserver.util.logging;

import java.io.*;
import java.util.logging.*;
import org.quickserver.net.InitServerHook;
import org.quickserver.net.server.QuickServer;

// Referenced classes of package org.quickserver.util.logging:
//            SimpleTextFormatter

public class SimpleJDKLoggingHook
    implements InitServerHook
{

    public SimpleJDKLoggingHook()
    {
    }

    public String info()
    {
        return "Init Server Hook to setup logging.";
    }

    public void handleInit(QuickServer quickserver)
        throws Exception
    {
        Logger logger = null;
        FileHandler txtLog = null;
        File log = new File("./log/");
        if(!log.canRead())
            log.mkdir();
        try
        {
            String level = System.getProperty("org.quickserver.util.logging.SimpleJDKLoggingHook.Level");
            logger = Logger.getLogger("");
            logger.setLevel(Level.FINEST);
            int count = 100;
            String temp = System.getProperty("org.quickserver.util.logging.SimpleJDKLoggingHook.Count");
            if(temp != null)
                try
                {
                    count = Integer.parseInt(temp);
                }
                catch(Exception exception) { }
            txtLog = new FileHandler((new StringBuilder("log/")).append(quickserver.getName()).append("_%u%g.txt").toString(), 0x100000, count, true);
            txtLog.setFormatter(new SimpleTextFormatter());
            setLevel(txtLog, level);
            logger.addHandler(txtLog);
            logger = Logger.getLogger("filesrv");
            quickserver.setAppLogger(logger);
        }
        catch(IOException e)
        {
            System.err.println((new StringBuilder("Could not create txtLog FileHandler : ")).append(e).toString());
            throw e;
        }
    }

    private static void setLevel(FileHandler target, String temp)
    {
        if(temp == null)
        {
            target.setLevel(Level.FINE);
            return;
        }
        temp = temp.toUpperCase();
        if(temp.equals("SEVERE"))
            target.setLevel(Level.SEVERE);
        else
        if(temp.equals("WARNING"))
            target.setLevel(Level.WARNING);
        else
        if(temp.equals("INFO"))
            target.setLevel(Level.INFO);
        else
        if(temp.equals("CONFIG"))
            target.setLevel(Level.CONFIG);
        else
        if(temp.equals("FINE"))
            target.setLevel(Level.FINE);
        else
        if(temp.equals("FINER"))
            target.setLevel(Level.FINER);
        else
        if(temp.equals("FINEST"))
            target.setLevel(Level.FINEST);
        else
        if(temp.equals("OFF"))
            target.setLevel(Level.OFF);
    }

    private QuickServer quickserver;
}
